/**
 * Copyright  2016
 *
 * 	All right reserved.
 *
 *	Created on  2016年3月8日 上午10:35:13
 * 
 */
package com.hongxinguoji.manager.site.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hongxinguoji.manager.common.util.EasyUIDataGridResult;
import com.hongxinguoji.manager.common.util.HXResult;
import com.hongxinguoji.manager.common.util.IDUtils;
import com.hongxinguoji.manager.site.pojo.HxSite;
import com.hongxinguoji.manager.site.service.ISiteService;

/**
 * @author liuh
 *
 */

@Controller
@RequestMapping("/site")
public class SiteController {

	@Resource
	private ISiteService siteService;

	/**
	 * 列表查询
	 * 
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/sitelist")
	@ResponseBody
	public EasyUIDataGridResult getSiteList(Integer page, Integer rows) {
		return siteService.getSiteList(page, rows);
	}

	/**
	 * 添加信息
	 * 
	 * @param site
	 * @return
	 */
	@RequestMapping("/addSite")
	@ResponseBody
	public HXResult addSite(HxSite site) {
		String id = IDUtils.getNumStringId();
		site.setId(id);
		siteService.addSite(site);
		return HXResult.ok();
	}

	/**
	 * 更新信息
	 * 
	 * @param site
	 * @return
	 */
	@RequestMapping("/updateSite")
	@ResponseBody
	public HXResult updateSite(HxSite site) {
		siteService.updateSite(site);
		return HXResult.ok();
	}

	/**
	 * 删除信息
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteSite")
	@ResponseBody
	public HXResult deleteSite(String ids) {
		try {
			String[] idStrings = ids.split(",");
			for (String id : idStrings) {
				siteService.deleteSite(id);
			}
			return HXResult.ok("删除信息成功");
		} catch (Exception e) {
			e.printStackTrace();
			return HXResult.ok("删除信息失败！");
		}
	}

	// 网站群页面跳转
	@RequestMapping("/{path}")
	public String goPath(@PathVariable String path) {
		return "site/" + path;
	}
}
